package com.sc.app.guanwang.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sc.commons.base.dto.BaseResponse;
import com.sc.commons.base.utils.except.BaseExceptionProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author
 */
@ControllerAdvice
public class GlobeExceptionAdvice {


    @Autowired
    private Environment environment;

    @Autowired
    private ObjectMapper objectMapper;

    @ResponseBody
    @ExceptionHandler(value = Throwable.class)
    public BaseResponse exception(Throwable e, HttpServletRequest request, HttpServletResponse response) throws Exception{
        return BaseExceptionProcess.process(e, environment, objectMapper, request, response);
    }
}
